
<!DOCTYPE html>
<html lang="zh">
<head>
    <title>CURD生成</title>
    <{include file="public/header"}>

</head>
<body class="hold-transition sidebar-mini layout-fixed">
<!-- Site wrapper -->
<div class="wrapper">
    <!-- 顶部导航 -->
    <{include file="public/navbar"}>
    <!--左侧菜单-->
    <{include file="public/sidebar"}>

    <div class="content-wrapper">
        <!-- 面包屑导航 -->
        <section class="content-header">
            <div class="container-fluid">
                <div class="row mb-2">
                    <div class="col-sm-6">

                    </div>
                    <div class="col-sm-6">
                        <ol class="breadcrumb float-sm-right">
                            <li class="breadcrumb-item"><a href="<{:url('/admin/index/index')}>">首页</a></li>
                            <li class="breadcrumb-item"><a href="#">自动化</a></li>
                            <li class="breadcrumb-item active">生成</li>
                        </ol>
                    </div>
                </div>
            </div>
        </section>

        <!-- 内容区-->
        <section class="content">
            <div class="container-fluid">
                <div class="row">
                    <!-- left column -->
                    <div class="col-md-12">

                        <div class="card card-primary">

                            <form method="post" action="<{:url('/admin/auto.index/run')}>" id="check-form">
                                <div class="card-body auto-form-item">
                                    <div class="form-group">
                                        <label for="table">数据表的名称</label>
                                        <input name="table" autocomplete="off" value="<{$data?$data.table:''}>" type="text" class="form-control" id="table" placeholder="表名">

                                        <span class="bs-red">需要生成代码的数据表名称 <a class="btn btn-xs btn-success check-table" href="javascript:void(0)">检测</a> </span>
                                    </div>



                                   <div class="auto-form-item-list"></div>






                                </div>
                                <div class="card-footer">
                                    <button type="button" onclick="layer.confirm('确定提交保存吗',{title:0},function() {
                                      form_submit()
                                    })" class="btn btn-primary">提交保存</button>
                                </div>
                            </form>
                        </div>

                    </div>

                </div>

            </div>
        </section>
    </div>

    <{include file="public/copyright"}>


</div>
<!-- ./wrapper -->

<{include file="public/footer"}>

<script>
    $(function () {
        $(".check-table").on('click',function () {
            let table = $("#table").val();
            if (!table.trim()){
                layer.msg('请输入表名');
                return false;
            }
            let url = "<{:url('ready')}>"
            sendData(url,{table:table},function (res) {
                console.log('res',res)
                if (res.code != 0){
                    return layer.msg(res.msg,{icon:5,time:2000})
                }

                let html = '';
                for (let i =0;i< res.data.fields.length; i++){
                    html += `<div class="form-group">
                                        <label for="${res.data.fields[i].name}">${res.data.fields[i].name}</label>
                                        <input style="width: 250px;display: inline" name="${res.data.fields[i].name}" autocomplete="off" value="${res.data.fields[i].comment}" type="text" class="form-control" id="${res.data.fields[i].name}" placeholder="请填写列表字段备注">

                                        <select style="width: 110px;display: inline" name="${res.data.fields[i].name}_note"  class="form-control" >

                                        <option value="0">非必填</option>
                                        <option ${res.data.fields[i].not_null==1?'selected':''}  value="1">必填</option>
</select>

                                        <span class="bs-red">${res.data.fields[i].comment} </span>
                                    </div>`
                }

                $(".auto-form-item-list").empty().html(html)
            },true,true)
        })
    })
</script>

</body>
</html>
